﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace cklib
{
    public class CookyDNSFilter
    {
        public Record[] Find(Record[] records, FindRecordParam find)
        {
            ArrayList taskArray = new ArrayList();
            foreach (Record info in records) taskArray.Add(info);

            if (find.fEnable)
            {
                int i = 0;
                while (taskArray.Count > i)
                {
                    Record record = (Record)taskArray[i];
                    if (find.FilterInfo.State != record.State)
                        taskArray.Remove(record);
                    else i++;
                }
            }
            if (find.fSubname)
            {
                int i = 0;
                while (taskArray.Count > i)
                {
                    Record record = (Record)taskArray[i];
                    if (find.FilterInfo.Subname != record.Subname)
                        taskArray.Remove(record);
                    else i++;
                }
            }
            if (find.fType)
            {
                int i = 0;
                while (taskArray.Count > i)
                {
                    Record record = (Record)taskArray[i];
                    if ((int)find.FilterInfo.Type != (int)record.Type)
                        taskArray.Remove(record);
                    else i++;
                }
            }

            if (find.fISP)
            {
                int i = 0;
                while (taskArray.Count > i)
                {
                    Record record = (Record)taskArray[i];
                    if (find.FilterInfo.Netmark != record.Netmark)
                        taskArray.Remove(record);
                    else i++;
                }
            }

            if (find.fValue)
            {
                int i = 0;
                while (taskArray.Count > i)
                {
                    Record record = (Record)taskArray[i];
                    if (find.FilterInfo.Value != record.Value)
                        taskArray.Remove(record);
                    else i++;
                }
            }
            return (Record[])taskArray.ToArray(typeof(Record));
        }
    }
    public class FindRecordParam
    {
        public Record FilterInfo = new Record();
        public bool fSubname = false;
        public bool fType = false;
        public bool fISP = false;
        public bool fValue = false;
        public bool Confirm = false;
        public bool fEnable = false;
    }
    public class ModifyRecordParam
    {
        public bool FillModify = false;
        public bool mSubname = false;
        public bool mType = false;
        public bool mISP = false;
        public bool mValue = false;
        public bool mEnable = false;
        public Record FillModifyRecord = new Record();
        public ModifyRecordParam()
        {
            FillModifyRecord.State = "ok";
            FillModifyRecord.ID = null;
            FillModifyRecord.Netmark = "默认";
            FillModifyRecord.MXLevel = 5;
            FillModifyRecord.Subname = "";
            FillModifyRecord.TTL = 3600;
            FillModifyRecord.Type = DNS_TYPE.TYPE_A;
            FillModifyRecord.Value = "";
        }
        public bool Confirm = false;
    }

}
